var TowerA = Tower.extend({
    ///////////////////////////////////////////////////////////
    ctor : function( filename,towerData ){//series,power,speed,fireRange,fireTime,bulletRes
        this._super(filename,towerData );
    },
    onEnter:function () {
        this._super();
    },
    onExit : function(){
        this._super();
    },
    ///////////////////////////////////////////////////////////
    dispatcher:function(){
        return "b0.png";
    },
    newBullet : function(){
        cc.log("new bullet");
        var name = MainResource(this.dispatcher()); // "res/"+this._bulletRes;
        var newBullet = new BulletA( name,this._power,this._speed,this._bulletType );
        newBullet.setPosition(this.getPosition());
        newBullet.setUserObject(this);
        newBullet._scope = this._fireRange;
        newBullet._life=true;
        newBullet._collide = false;
        // set bullet size
        this.addBullet(newBullet);
    },
    reviveBullet : function(bullet){
        bullet.setPosition(this.getPosition());
        bullet.setPower(this._power);
        bullet.setSpeed(this._speed);
        bullet.revive(this._fireRange);
    },
    enableFire : function(){
        var that=this;
        this.runAction( cc.Sequence.create(
            new cc.DelayTime( this._fireTime ),
            new cc.CallFunc( function(){ that._canFire = true;cc.log("open fire trigger");} )
        ));
    },
    fighting : function(direct){
        if ( this._canFire ){ // this._canFire
            var distance = cc.pDistance(this.getPosition(),direct );
            if ( distance<this._fireRange ){
                this._canFire = false;
                cc.log("distance: "+distance);
                var bullet = this.getBulletFromBuffer();
                if ( bullet ){
                    this.reviveBullet(bullet);
                }else{
                    this.newBullet(direct,distance);
                }
                var filename = AudioResource("sun.mp3");
                cc.audioEngine.playEffect(filename);
                return true;
            }
        }
        return false;
    }
});
////////////////////////////////////////////////////////////////
TowerA.create = function (filename,towerData ) {
    var tower = new TowerA(filename,towerData );
    return tower;
};

